package ${location};

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${location}.model.dto.${camelClassName}.${className}AddDto;
import ${location}.model.dto.${camelClassName}.${className}PageDto;
import ${location}.model.entities.${className};
import ${location}.model.vo.${camelClassName}.${className}Vo;
import ${location}.service.${className}Service;
import org.junit.Test;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = MainApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@Transactional(rollbackFor = Exception.class)
@Rollback
@RunWith(SpringRunner.class)
public class ${className}ServiceTest {

	@Autowired
	private ${className}Service ${camelClassName}Service;
	private ${className} ${camelClassName};

	@Before
	public void before() {
		IPage<${className}> page = new Page<>(1, 1);
		${camelClassName}Service.page(page);
		${camelClassName} = page.getRecords().get(0);
	}


	@Test
	public void saveEntity() {
		${className}AddDto dto = new ${className}AddDto();
		BeanUtils.copyProperties(${camelClassName}, dto);
		${className}Vo vo = ${camelClassName}Service.saveEntity(dto);
		System.out.println(vo);
	}

	@Test
	public void deleteEntityById() {
		${idType} num = ${camelClassName}Service.deleteEntityById(${camelClassName}.getId());
		System.out.println(num);
	}

	@Test
	public void updateEntityById() {
		${className}AddDto dto = new ${className}AddDto();
		BeanUtils.copyProperties(${camelClassName}, dto);
		${className}Vo vo = ${camelClassName}Service.updateEntityById(${camelClassName}.getId(), dto);
		System.out.println(vo);
	}

	@Test
	public void getEntityById() {
		${className}Vo vo = ${camelClassName}Service.getEntityById(${camelClassName}.getId());
		System.out.println(vo);
	}

	@Test
	public void pageQueryEntities() {
		${className}PageDto dto = new ${className}PageDto();
		dto.setPage(1);
		dto.setSize(5);
		IPage<${className}Vo> iPage = ${camelClassName}Service.pageQuery(dto);
		iPage.getRecords().forEach(System.out::println);
	}
}
